/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.user;

import ipostservices.model.bean.Project;
import ipostservices.services.ProjectSrv;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author sup3rm4r10
 */
public class CargarProyectosVista extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            /*
             * TODO output your page here. You may use following sample code.
             */
//            ProjectSrv proyecto = new ProjectSrv();
//            List <Project> proyectos = proyecto.getProys();
            
            out.println("<html>");
            out.println("<head>");
            out.println("<link rel='stylesheet' type='text/css' href='Estilos/misEstilos.css'>");
            out.println("<title>Alta de Usuarios</title>");
            out.println("<script>");
            out.println("var EvRegister=[];");
            out.println("var panino=(function(){");
            out.println("var metodosPrivados={");
            out.println("addEvent: function(type, fn ) {");
            out.println("if ( this.addEventListener ) {");
            out.println("this.addEventListener( type, fn, false );");
            out.println("} else if(this.attachEvent){");
            out.println("var _this=this;");
            out.println("var f= function(){fn.call(_this,window.event);}");
            out.println("this.attachEvent( 'on'+type, f);");
            out.println("this[fn.toString()+type]=f;");
            out.println("}else{");
            out.println("this['on'+type]=fn;");
            out.println("}var ev={_obj:this,_evType:type,_fn:fn};");
            out.println("window.EvRegister.push(ev);");
            out.println("return this;");
            out.println("},removeEvent: function(type, fn ) {");
            out.println("if( this.removeEventListener){");
            out.println("this.removeEventListener( type, fn, false );");
            out.println("}else if(this.detachEvent){");
            out.println("this.detachEvent('on'+type,this[fn.toString()+type]);");
            out.println("this[fn.toString()+type]=null;");
            out.println("}else{	this['on'+type]=function(){};");
            out.println("}for (var ii= 0, l=window.EvRegister.length; ii < l ; ii++) {");
            out.println("if (window.EvRegister[ii]._evType== type && window.EvRegister[ii]._obj==this && window.EvRegister[ii]._fn==fn) {");
            out.println("window.EvRegister.splice(ii, 1);");
            out.println("break;}}");
            out.println("return this;");
            out.println("}, css:function(propiedad,valor){");
            out.println("if(!valor)");
            out.println("return this.style[propiedad];");
            out.println("this.style[propiedad]=valor;");
            out.println("return this;");
            out.println("}, hover:function(a,b){");
            out.println("this.addEvent('mouseover', a );");
            out.println("this.addEvent('mouseout', b );");
            out.println("return this;");
            out.println("}, alfa:function(value){");
            out.println("this.style.opacity = value;");
            out.println("this.style.MozOpacity = value;	this.style.KhtmlOpacity = value;");
            out.println("this.style.filter = 'alpha(opacity=' + value*100 + ')';");
            out.println("this.style.zoom=1;");
            out.println("return this;");
            out.println("},toggle:function(a,b){");
            out.println("this.style.display=this.style.display=='none'?'block':'none';");
            out.println("if(!!a && !!b)");
            out.println("a.parentNode.replaceChild(b,a);");
            out.println("return this;");
            out.println("},extendido:true}");
            out.println("return{	extend:function(el,obj){");
            out.println("if(el.extendido && el!=metodosPrivados)return el;");
            out.println("for(var i in obj)");
            out.println("el[i]=obj[i];");
            out.println("return el;");
            out.println("},get:function(id){");
            out.println("if(!document.getElementById(id))return false;");
            out.println("return panino.extend(document.getElementById(id),metodosPrivados);");
            out.println("},getO:function(obj){");
            out.println("return panino.extend(obj,metodosPrivados);");
            out.println("},add:function(obj){");
            out.println("panino.extend(metodosPrivados,obj);");
            out.println("}}})();");
            out.println("function unregisterAllEvents() {");
            out.println("while (EvRegister.length > 0) {");
            out.println("panino.getO(EvRegister[0]._obj).removeEvent(EvRegister[0]._evType,EvRegister[0]._fn);");
            out.println(" }}");
            out.println("var $=panino.get;");
            out.println("panino.getO(window).addEvent('unload',unregisterAllEvents);");
            out.println("function Acordeon(id,abierto){");
            out.println("this.abierto=abierto || 0;");
            out.println("this.id=id;");
            out.println("this.init=function(){");
            out.println("var _this=this;");
            out.println("for(var i=0,els; els=$(this.id).getElementsByTagName('dt')[i];i++){");
            out.println("var maxExpand=$(this.id).getElementsByTagName('dd')[i].offsetHeight;");
            out.println("if(!this.abierto || this.abierto!=i+1){");
            out.println("$(this.id).getElementsByTagName('dd')[i].style.height=0;");
            out.println("$(this.id).getElementsByTagName('dd')[i].style.display='none';");
            out.println("$(this.id).getElementsByTagName('dd')[i].creciendo=1;");
            out.println("}else{");
            out.println("$(this.id).getElementsByTagName('dd')[i].creciendo=0;");
            out.println("$(this.id).getElementsByTagName('dd')[i].style.height=maxExpand+'px';}");
            out.println("(function(){");
            out.println("var _maxExpand=maxExpand;");
            out.println("var numero=i;");
            out.println("panino.getO(els).addEvent('click',function(){_this.efectuar(_maxExpand,numero);}).css('cursor','pointer');");
            out.println("})()");
            out.println("}$(this.id).css('visibility','visible');");
            out.println("}");
            out.println("this.efectuar=function(maximo,elemento){");
            out.println("var _this=this;");
            out.println("if($(_this.id).getElementsByTagName('dd')[elemento].t!=null && typeof $(_this.id).getElementsByTagName('dd')[elemento].t!='undefined' && $(_this.id).getElementsByTagName('dd')[elemento].t.done_!=true)return;");
            out.println("var inicio=parseInt($(this.id).getElementsByTagName('dd')[elemento].style.height);");
            out.println("var fin= $(_this.id).getElementsByTagName('dd')[elemento].creciendo ? maximo  : 0; ");
            out.println("$(_this.id).getElementsByTagName('dd')[elemento].creciendo=!$(_this.id).getElementsByTagName('dd')[elemento].creciendo;");
            out.println(" $(_this.id).getElementsByTagName('dd')[elemento].t=new Transition(SineCurve, 500, function(percentage) {");
            out.println("if(fin<inicio){ ");
            out.println("var delta=inicio-fin; ");
            out.println("$(_this.id).getElementsByTagName('dd')[elemento].style.height=(inicio-(percentage*delta))+'px'; ");
            out.println("}else{ ");
            out.println("var delta=fin-inicio; ");
            out.println("$(_this.id).getElementsByTagName('dd')[elemento].style.height=(inicio+(percentage*delta))+'px'; ");
            out.println("}if(parseInt($(_this.id).getElementsByTagName('dd')[elemento].style.height)<1) ");
            out.println("$(_this.id).getElementsByTagName('dd')[elemento].style.display='none'; ");
            out.println("else ");
            out.println("$(_this.id).getElementsByTagName('dd')[elemento].style.display='block'; ");
            out.println("}); ");
            out.println("$(_this.id).getElementsByTagName('dd')[elemento].t.run(); ");
            out.println("}} ");
            out.println("function Transition(curve, milliseconds, callback) { ");
            out.println("this.done_=false; ");
            out.println("this.curve_ = curve; ");
            out.println("this.milliseconds_ = milliseconds; ");
            out.println("this.callback_ = callback; ");
            out.println("this.start_ = new Date().getTime(); ");
            out.println("this.run=function() { ");
            out.println("var _this=this; ");
            out.println("if(!this.hasNext()) { ");
            out.println("window['globalIntervalo']=0; ");
            out.println("return; ");
            out.println("}this.callback_(this.next()); ");
            out.println("setTimeout(function(){_this.run.call(_this);}, 0);");
            out.println("}");
            out.println("this.hasNext=function() { ");
            out.println("if(this.done_) ");
            out.println("return false; ");
            out.println("var now = new Date().getTime(); ");
            out.println("if ((now - this.start_) > this.milliseconds_) { ");
            out.println("this.done_ = true; ");
            out.println("}return true ");
            out.println("}");
            out.println("this.next=function() { ");
            out.println("var now = new Date().getTime(); ");
            out.println("var percentage = Math.min(1, (now - this.start_) / this.milliseconds_); ");
            out.println("return this.curve_(percentage); ");
            out.println("} ");
            out.println("} ");
            out.println("function SineCurve(percentage) { ");
            out.println("return (1 - Math.cos(percentage * Math.PI)) / 2; ");
            out.println("} ");
            out.println("onload=function(){ ");
            out.println("var t=new Acordeon('lista'); ");
            out.println("t.init(); ");
            out.println("} ");
            out.println("</script> ");
            out.println("</head> ");
            out.println("<body> ");
            out.println("<div id='cuerpo'></div> ");
            out.println("<div id='imagenpost'> <img src='Imagenes/ico.png' alt='postit' />  </div>");
            out.println("<article> ");
            out.println("<section id='Title'> ");
            out.println("<h2 style='font-family:Arial, Helvetica, sans-serif; font-size:20px'>Alta de Usuario</h2> ");
            out.println("Por favor llene los campos con la informacion que se le pide. ");
            out.println("<section id='Form'> ");
            out.println("<form action='AltaUsuario' method='post'> ");
            out.println("<table style='position:absolute; left:30px; top:20px' > ");
            out.println("<tr> ");
            out.println("<td width='297'> ");
            out.println("Nombre de usuario:</br> <input type='text'  size='30' name='usuario' autofocus/> ");
            out.println(" </td> ");
            out.println("</tr> ");
            out.println("<tr> ");
            out.println("<td> ");
            out.println("Email:</br> <input type='text'  size='30' name='mail' /> ");
            out.println("</td> ");
            out.println("<td width='21'><pre></pre></td> ");
            out.println("</tr> ");
            out.println("<tr> ");
            out.println("<td> ");
            out.println("Contraseña:</br> <input type='password' size='30' name='contrasena' /> ");
            out.println("</td> ");
            out.println("</tr> ");
            out.println("<tr>&nbsp;</tr><tr>&nbsp;</tr><tr>&nbsp;</tr><tr>&nbsp;</tr> ");
            out.println("<tr> ");
            out.println("<td> ");
            out.println("<input type='submit' value='Guardar' /> ");
            out.println("</td> ");
            out.println(" </tr> ");
            out.println("<table style='position:absolute; left:350px; top:30px'> ");
            out.println("<tr> ");
            out.println("<td> ");
            
            out.println("<dl id='lista'>");
            out.println("<dt>Proyectos<div id='flecha'></div></dt>");
            out.println("<dd>");
//            for(int i=1;i<proyectos.size();i++){
//                out.println("<input name='"+i+"' type='checkbox' value='"+proyectos.get(i).getIdproject()+"' />"+ proyectos.get(i).getTitulo() +"<br/>");
//            }
            out.println("</dd>");
            out.println("</dl>");
            
            out.println("</td> ");
            out.println(" </tr> ");
            out.println("</table> ");
            out.println("</table> ");
            out.println(" </form> ");
            out.println("</section> ");
            out.println("</section> ");
            out.println("</article> ");
            out.println("<footer id='pie'> ");
            out.println("copyRight <br> Mario cortes &copy; ");
            out.println("</footer> ");
            out.println("</body> ");
            out.println("</html> ");
              
        } finally {            
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
